property kasOpenWindowWhenRun : true -- Set to false to not open the remote item's window in the Finder when run
property kasAllowAlerts : true -- Set to false to stop any alerts from appearing
property kasServerAlerts : true -- Set to false to stop warnings about missed servers
property kasFinder : "Finder" -- name of application to open RemoteLaunchers
property kasAppendage : " ->" -- Appended to file name if we can't use original
property kasPrefixLauncher : "≈ " -- Prefix named of launchers with these characters.
property kasJustDoIt : true -- Don't ask so many questions - just do it!
-- Internal/User setable globals
property gasLinkSet : false -- Has the friend been asked for? - set to true to never ask
property gasLinkNeed : false
property kasLinkUserDft : "CasaVision" -- Defaults for linking access
property kasLinkPassDft : ""
property gasServSet : false
property gasServNeed : false
property kasServUserDft : "Synapse" -- Defaults for server access
property kasServPassDft : ""
property kasServNTDft : ""
-- Internal globals
global gasLinkUser -- Our friend on all machines
global gasLinkPass -- Our friend's password on all machines
global gasServUser -- Our friend on all machines
global gasServPass -- Our friend's password on all machines
global gasServNT -- Volume password
property gasOurAlias : "" -- The alias we own
property gasOurStatus : "" -- Empty, "RemoteLauncher" or "RemoteFolder"
property gasOurServer : "" -- Set to server of gasOurAlias
property gasOurZone : "" -- Set to zone of gasOurAlias
property gasOurName : "" -- Name of original alias
property gasOurVol : "" -- Name of volume alias resides on
property gasOurType : "" -- If we are a RemoteLauncher, this is our file type
property gasCopyLoc : {-1, -1} -- The location of the copy window
-- Remote access stuff
property kraConnected : "connected" -- ARA osax strings
property kraProtocol : "ARAP"
property gasRemote : false -- set internally to true if volume was a RemoteAccess volume
property gasRemoteCfg : "" -- Set internally to ARA config needed for this access
property gasRemoteModem : "" -- Set internally to modem for RA connection
property gasRemoteServer : "" -- Set internally to check if we are already connected to the correct server
property gasRemoteAlias : false --Set internally to rebuild ARA with alias instead of osax
property gasRemoteNum : "" -- Set internally to the telephone number of the remote machine
property gasRemoteUsr : "" -- Set internally to the login user for the remote machine
on run
if (gasOurStatus is "") then
ShowInitAlert()
else if (gasOurStatus is "RemoteLauncher") then
RunRemoteLauncher()
else if (gasOurStatus is "RemoteFolder") then
RunRemoteFolder(kasOpenWindowWhenRun)
else
beep
end if
end run
on open fsObjs
if option key down of (input state) then
if the number of items in fsObjs is not 1 then
ShowInitAlert()
else if (ShowChoice("You have the option key pressed." & return & return & ¬
"Do you wish to reinitialize this script with the object you dropped on it?")) then
SetScriptAlias(item 1 of fsObjs)
end if
else if (gasOurStatus is "") then
if the number of items in fsObjs is not 1 then
ShowInitAlert()
else
SetScriptAlias(item 1 of fsObjs)
end if
else if (gasOurStatus is "RemoteLauncher") then
(*
What we want to do here if the file dropped on us is on
the same server as our alias:
If we are a document and an application is dropped on us,
we open us with that application. If we are an application
and a document is dropped on us we open that document with
this application.
*)
-- Get the user/password
if not GetFriend(false) then return
set cantOpen to false
set iAmApp to (gasOurType is "APPL")
repeat with fsObj in fsObjs
set aInfo to alias info from fsObj
if the alias server of aInfo is not gasOurServer then
set cantOpen to true
else
set fInfo to basic info for fsObj
set isAnApp to (system type of fInfo is "APPL")
if (iAmApp is isAnApp) then
set cantOpen to true
else
if (iAmApp) then
set appAli to gasOurAlias
set docAli to fsObj
else
set appAli to fsObj
set docAli to gasOurAlias
end if
if (not RemoteLaunchUsing(appAli, docAli)) then return
end if
end if
end repeat
if (cantOpen) then ShowOpenAlert()
else if (gasOurStatus is "RemoteFolder") then
set wasMounted to IsVolMounted(gasOurVol)
if (RunRemoteFolder(false)) then
repeat with fsObj in fsObjs
try
set gasCopyLoc to (AkuaCopy fsObj located at gasCopyLoc with resuming given «class Dest»:gasOurAlias)
on error err
ShowAlert("An error (" & (err as string) & ") occured copying “" & (fsObj as string) & "”. The network may have been interrupted or a disk error may have occured")
end try
end repeat
if (not wasMounted) then ¬
PutAwayVol(gasOurVol)
end if
end if
end open
on RunRemoteFolder(openInFinder)
-- Get the user/password
if not GetFriend(false) then return
set mounted to false
-- Mount the remote volume if we weren't ARA connected.
if (not gasRemote or not gasRemoteAlias) then
try
«event ÅkuNMSVm» gasOurVol ¬
given «class VPwd»:gasServNT, «class ZONE»:gasOurZone ¬
, «class USER»:gasServUser ¬
, «class PASS»:gasServPass ¬
, «class SRVR»:gasOurServer
set mounted to true
on error
if (CouldBeSharing(gasOurZone, gasOurServer)) then
try
«event ÅkuNMSVm» gasOurVol ¬
given «class VPwd»:gasServNT, «class ZONE»:gasOurZone ¬
, «class USER»:gasServUser ¬
, «class PASS»:gasServPass ¬
, «class SRVR»:gasOurServer ¬
on error
if (kasServerAlerts) then
ShowMountAlert()
else
beep
end if
set mounted to false
end try
else
if (kasServerAlerts) then
ShowMountAlert()
else
beep
end if
set mounted to false
end if
end try
end if
if (mounted) then
try
set gfiDestFolder to «event ÅkuNResW» gasOurAlias ¬
given «class VPwd»:gasServNT, «class USER»:gasServUser, «class PASS»:gasServPass ¬
-- Tell Finder to open the alias now that it is mounted
if (openInFinder) then
tell application kasFinder
open gasOurAlias
activate
end tell
end if
on error
set mounted to false
if (kasServerAlerts) then
ShowAliasAlert()
else
beep
end if
end try
end if
return mounted
end RunRemoteFolder
on RunRemoteLauncher()
-- Get the user/password
if not GetFriend(false) then return
if (gasOurServer is "") then
set suspect to application kasFinder
else
talk as user gasLinkUser ¬
with password gasLinkPass ¬
on server gasOurServer ¬
in AppleTalk zone gasOurZone
set suspect to application kasFinder ¬
of machine gasOurServer ¬
of zone gasOurZone
end if
try
-- Don't wait for a response, assume the aliases are correct?
tell suspect to open gasOurAlias
on error
if (kasServerAlerts) then
ShowConnectAlert(kasFinder)
else
beep
end if
end try
end RunRemoteLauncher
on RemoteLaunchUsing(appAli, docAli)
set aName to original name of (alias info from appAli)
if (gasOurServer is "") then
-- Don't wait for a response, assume the aliases are correct
tell application kasFinder ¬
to open docAli given «class usin»:appAli
else
talk as user gasLinkUser ¬
with password gasLinkPass ¬
on server gasOurServer ¬
in AppleTalk zone gasOurZone
-- Is the app running?
if (the server processes aName on server gasOurServer in AppleTalk zone gasOurZone ¬
as user name gasLinkUser with password gasLinkPass) is not "" then
try
tell application aName of machine gasOurServer ¬
of zone gasOurZone to open docAli
on error
ShowConnectAlert(aName)
end try
else
try
-- Don't wait for a response, assume the aliases are correct
tell application kasFinder of machine gasOurServer ¬
of zone gasOurZone to open docAli given «class usin»:appAli
on error
if (kasServerAlerts) then
ShowConnectAlert(kasFinder)
else
beep
end if
return false
end try
end if
end if
return true
end RemoteLaunchUsing
on ChooseScriptAlias()
if ShowChoices("Do you wish to activate this script with a folder/volume or a file?", {"Folder", "File"}) is "File" then
set myObj to ¬
choose file with prompt "Choose a server file for this PowerScript RA"
else
set myObj to ¬
choose folder with prompt "Choose a server folder or volume for this PowerScript RA"
end if
SetScriptAlias(myObj)
end ChooseScriptAlias
on SetScriptAlias(aliasObj)
-- My Path
set myPath to (path to me)
-- Grab an alias
set gasOurAlias to aliasObj
set aInfo to alias info from aliasObj
set fInfo to basic info for aliasObj
-- Save the info we need
set gasOurServer to alias server of aInfo
set gasOurZone to alias zone of aInfo
set gasOurVol to alias volume of aInfo
set gasOurName to original name of aInfo
-- Remote info
set gasRemoteNum to ARA number of aInfo
set gasRemoteUsr to ARA user of aInfo
set gasRemotePwd to ARA password of aInfo
set gasOurType to system type of fInfo
set newName to gasOurName -- Start with name of original item
-- What will we be - a mounter or a launcher?
if (catalog kind of fInfo) is a folder then
set gasOurStatus to "RemoteFolder"
set gasServNeed to true
else
set gasOurStatus to "RemoteLauncher"
set gasLinkNeed to true
set newName to kasPrefixLauncher & newName
end if
-- Try to set our name to dropped name
try
collate myPath renaming it to newName
on error
-- If we can't use the original name, try an appendage :)
try
collate myPath renaming it to newName & kasAppendage
on error
beep
end try
end try
-- Get the user/password
GetFriend(false)
-- Check ARA connection
set gasRemote to IsRemoteAccessed()
if (gasRemote) then
WantRemoteAccess()
if (gasRemoteAlias) then ¬
GetOneFriend(false, false) -- Need to preflight server if we will be resolving the alias for the ARA connection
end if
-- Set our icon to dropped icon
set ourIcon to (the icon for aliasObj)
set the icon of myPath to ourIcon
try
tell application "Finder" to update myPath -- Double dose?
on error
beep
end try
end SetScriptAlias
on GetFriend(override)
set gasLinkUser to kasLinkUserDft
set gasLinkPass to kasLinkPassDft
set gasServUser to kasServUserDft
set gasServPass to kasServPassDft
set gasServNT to kasServNTDft
if (gasOurServer is "") then -- Local?
set gasLinkSet to true
set gasServSet to true
else
-- Build ARA connection?
if (gasRemote and not gasRemoteAlias) then
if not BuildRemoteAccess() then return false
end if
-- Get linking (and server) user?
if (gasLinkNeed) then
GetOneFriend(true, override)
if (gasRemote and gasRemoteAlias) then ¬
GetOneFriend(false, override)
end if
-- Get server user?
if (gasServNeed) then GetOneFriend(false, override)
end if
return true
end GetFriend
on GetOneFriend(isLink, override)
if (isLink) then
set userMode to "linking"
if (gasLinkSet) then
set defUser to gasLinkUser
set defPass to gasLinkPass
end if
set defNT to kasServNTDft
set passButtons to {"Cancel", "OK"}
set passButton to 2
else
set userMode to "sharing"
if (gasServSet) then
set defUser to gasServUser
set defPass to gasServPass
set defNT to gasServNT
end if
set passButtons to {"Cancel", "NT Password…", "OK"}
set passButton to 3
end if
set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
if (override or usrPwd is {}) then
set chosen to display dialog ¬
"Enter the friendly " & userMode & ¬
" user's name for the server \"" & gasOurServer ¬
& "\"…" default answer defUser ¬
default button 2 with icon note
if (the button returned of chosen is "OK") then
set defUser to the text returned of chosen
else
return
end if
set chosen to display dialog ¬
"Enter the friendly " & userMode & ¬
" user's password…" buttons passButtons ¬
default answer defPass default button passButton with icon note
if (the button returned of chosen is not "Cancel") then
set defPass to the text returned of chosen
else
return
end if
if (the button returned of chosen is "NT Password…") then
set chosen to display dialog ¬
"Enter the volume password for Windoze NT…" default answer ¬
defNT default button 2 with icon note
if (the button returned of chosen is not "Cancel") then